package org.syndicate.domain;

import org.springframework.roo.addon.entity.RooEntity;
import org.springframework.roo.addon.javabean.RooJavaBean;
import org.springframework.roo.addon.tostring.RooToString;
import org.springframework.transaction.annotation.Transactional;

import java.util.Set;
import org.syndicate.domain.Share;

import sun.reflect.generics.reflectiveObjects.NotImplementedException;

import java.util.HashSet;
import javax.persistence.ManyToMany;
import javax.persistence.CascadeType;

/**
 * Expresses how to share SharePie. 
 * 
 * @author akiraabe
 */
@RooJavaBean
@RooToString
@RooEntity
public class SharePie {

	private Double amount;

	private String name;
	
	private String discriminator;
	
	@ManyToMany(cascade = CascadeType.ALL)
	private Set<Share> shares = new HashSet<Share>();

	/**
	 * At first, SharePie is made adding up Share.
	 */
	@Transactional
	public void create() {
		System.out.println("SharePie#create");
		throw new NotImplementedException();
	}

	/**
	 * Prorate new share pie.
	 * 
	 * @param amount of SharePie
	 * @return new SharePie that includes some shares.
	 */
	protected SharePie prorate(Double amount) {
		System.out.println("SharePie#prorate");
		throw new NotImplementedException();
	}

	/**
	 * Transfer share from a company to another company.
	 * 
	 * @param from
	 * @param to
	 * @param num
	 */
	public void transfer(Company from, Company to, Double num) {
		System.out.println("SharePie#transfer");
	}

	/**
	 * Add share to share pie.
	 * @param share
	 */
	void addShare(Share share) {
		shares.add(share);
	}
}
